# class Solution:
#     def maxNumber(self, nums1, nums2, k: int):
#         def findmaxseq(n,nums):            
#             subseq=[]
#             def findnext(n,offset):
#                 if n==0:
#                     return 
#                 maxindex=offset
#                 for i in range((len(nums)-offset)-n+1):
#                     if nums[offset+i]>nums[maxindex]:
#                         maxindex=offset+i
#                 subseq.append(nums[maxindex])
#                 findnext(n-1,maxindex+1)
#             findnext(n,0)
#             return subseq
#         def compare( seq1, index1: int, seq2, index2: int) -> int:
#             x, y = len(seq1), len(seq2)
#             while index1 < x and index2 < y:
#                 difference = seq1[index1] - seq2[index2]
#                 if difference != 0:
#                     return difference
#                 index1 += 1
#                 index2 += 1
#             return (x - index1) - (y - index2)

#         def merge(seq1,seq2):
#             nonlocal k
#             if len(seq1)==0:
#                 return seq2
#             if len(seq2)==0:
#                 return seq1
#             offset1=0
#             offset2=0
#             seq=[]
#             for i in range(k):
#                 if compare(seq1,offset1,seq2,offset2)>=0:
#                     seq.append(seq1[offset1])
#                     offset1+=1     
#                 else:                  
#                     seq.append(seq2[offset2])
#                     offset2+=1
#             return seq
#         start,end=max(0,k-len(nums2)),min(k,len(nums1))
#         maxseq=[0]*k
#         for i in range(start,end+1):
#             curr=merge(findmaxseq(i,nums1),findmaxseq(k-i,nums2))
#             if compare(maxseq,0,curr,0)<0:
#                 maxseq=curr
#         return maxseq

                
    

                

def getMaxSubsequence( nums, k: int) -> int:
    stack = [0] * k
    top = -1
    remain = len(nums) - k

    for i, num in enumerate(nums):
        while top >= 0 and stack[top] < num and remain > 0:
            top -= 1
            remain -= 1
        if top < k - 1:
            top += 1
            stack[top] = num
        else:
            remain -= 1
        print(stack,top,remain,k)    
    return stack

getMaxSubsequence([3,4,6,5],3)

